/**
 * Created by wangjz on 2019/02/26.
 */
import React, { Component, PropTypes } from 'react';
import { Divider, Icon, Select, Tree } from 'antd/lib/index';
import { listCategory } from './Service';

class Category extends Component {

  state = {
    categoryList: [],
  };

  constructor(props) {
    super(props);
    this.init();
  }

  init = async () => {
    let categoryList = await listCategory(this.props.type);

    if (this.props.edit == false) {
      categoryList.splice(0, 0, { id: 0, name: '全部', type: 1 });
    }
    this.setState({ categoryList: categoryList, value: this.props.value });
  };


  handleSelectTree = selectedKey => {
    this.props.handleSelectTree(selectedKey);
  };

  onChange = (value) => {
    this.setState({ value: value });
  };

  render() {
    return (
      <Select style={{ width: this.props.width }} value={this.state.value} onChange={this.onChange}>
        {this.state.categoryList.map(item => {
          return <Select.Option key={item.id} value={item.id}>{item.name}</Select.Option>;
        })}
      </Select>
    );
  }
}

export default Category;
